import 'package:flutter/material.dart';
import 'cart_page.dart';
import 'cate_page.dart';
import 'home_page.dart';
import 'member_page.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class Indexpage extends StatefulWidget {
  @override
  _IndexpageState createState() => _IndexpageState();
}

class _IndexpageState extends State<Indexpage> {
  final List<BottomNavigationBarItem> bottomTabs = [
    BottomNavigationBarItem(icon: Icon(Icons.vertical_align_center),
    title: Text('首页')),
    BottomNavigationBarItem(icon: Icon(Icons.search),
    title: Text('分类')),
    BottomNavigationBarItem(icon: Icon(Icons.shopping_cart),
    title: Text('购物车')),
    BottomNavigationBarItem(icon: Icon(Icons.portable_wifi_off),
    title: Text('会员中心')),
  ];
  final List<Widget> tabButtom = [
    Homepage(),
    Catepage(),
    Cartpage(),
    Memberpage()
  ];
  int indexs = 0;
  var pages;
  @override
  void initState() {
      pages = tabButtom[indexs];
    // TODO: implement initState
    super.initState();
  }


  @override
  Widget build(BuildContext context) {
   ScreenUtil.instance = ScreenUtil(width: 750,height: 1624)..init(context);
    return Scaffold(
      backgroundColor: Color.fromRGBO(255, 51, 51, 1),
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        currentIndex: indexs,
        items: bottomTabs,
        onTap: (index){
          setState(() {
            indexs = index;
            pages = tabButtom[indexs];
            
          });
        },
      ),
      body: IndexedStack(
        index:indexs,
        children:tabButtom,
      ),
    );
  }
}

